from pwn import *
import requests
from bs4 import BeautifulSoup

context.log_level = 'debug'
url = 'http://178.128.163.152:31406/'
cookies = {'PHPSESSID': 'b54ngfqc6v49997pplred5kad1'}

response = requests.get(url, cookies=cookies)  # Initial request

# Loop until we see the flag
while 'HTB' not in response.text:
    # Extract the phrase from <h3>
    extracted = BeautifulSoup(response.text, features="lxml").h3.contents[0]
    debug('extracted: %s', extracted)

    # MD5 the extracted string
    hashed = md5sumhex(extracted.encode())
    debug('hash: %s', hashed)

    # Submit the hash
    response = requests.post(url, data={'hash': hashed}, cookies=cookies)

# Print the response if we got the flag
extracted = BeautifulSoup(response.text, features="lxml").p.contents[0]
warn(extracted)
